home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / GNUPLOTsrc.lha / term / hpgl.trm < prev    next >
Encoding:
Text File  |  1996-01-22  |  17.2 KB  |  784 lines

  1. /*
  2.  * $Id: hpgl.trm,v 1.13 1995/12/20 21:47:53 drd Exp $
  3.  */
  4.  
  5. /* GNUPLOT - hpgl.trm */
  6. /*
  7.  * Copyright (C) 1990   
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted, 
  11.  * provided that the above copyright notice appear in all copies and 
  12.  * that both that copyright notice and this permission notice appear 
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the modified code.  Modifications are to be distributed 
  17.  * as patches to released version.
  18.  *  
  19.  * This software  is provided "as is" without express or implied warranty.
  20.  * 
  21.  * This file is included by ../term.c.
  22.  *
  23.  * This terminal driver supports:
  24.  *  hpgl, hp7550, hp7580b, HP Laserjet III
  25.  *  hp7550 has been replaced by  "hpgl 8 eject"
  26.  *  hp7580b has been replaced by "hpgl 4"
  27.  *
  28.  * AUTHORS
  29.  *  Colin Kelley, Thomas Williams, Russell Lang
  30.  * 
  31.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  32.  * 
  33.  */
  34.  
  35. /*
  36.  *
  37.  * MODIFIED for expanded HPGL/2 and PCL utilites
  38.  *  Tom Swiler (tom@silica.mse.ufl.edu)
  39.  * Modified June 1995 Ian MacPhedran to support newterm format
  40.  * Modified October 1995 Ian MacPhedran to simplify HPGL terminals
  41.  * 
  42.  */
  43. #define HPGL
  44. #define PCL
  45.  
  46. #ifndef GOT_DRIVER_H
  47. #include "driver.h"
  48. #endif /* GOT_DRIVER_H */
  49.  
  50. #ifdef TERM_REGISTER
  51. register_term(hpgl)
  52. register_term(pcl5)
  53. #endif /* TERM_REGISTER */
  54.  
  55. #ifdef TERM_PROTO
  56. TERM_PUBLIC void HPGL_options __P((void));
  57. TERM_PUBLIC void HPGL2_options __P((void));
  58. TERM_PUBLIC void PCL_options __P((void));
  59. TERM_PUBLIC void HPGL_init __P((void));
  60. /* TERM_PUBLIC void HPGL2_init __P((void)); */
  61. TERM_PUBLIC void PCL_init __P((void));
  62. TERM_PUBLIC void HPGL_graphics __P((void));
  63. TERM_PUBLIC void HPGL2_graphics __P((void));
  64. TERM_PUBLIC void PCL_graphics __P((void));
  65. TERM_PUBLIC void HPGL_text __P((void));
  66. /* TERM_PUBLIC void HPGL2_text __P((void)); */
  67. /* TERM_PUBLIC void PCL_text __P((void)); */
  68. TERM_PUBLIC void HPGL_linetype __P((int linetype));
  69. TERM_PUBLIC void HPGL2_linetype __P((int linetype));
  70. TERM_PUBLIC void HPGL_put_text __P((unsigned int x, unsigned int y, char *str));
  71. TERM_PUBLIC void HPGL2_put_text __P((unsigned int x, unsigned int y, char *str));
  72. TERM_PUBLIC void HPGL_move __P((unsigned int x, unsigned int y));
  73. TERM_PUBLIC void HPGL_vector __P((unsigned int x, unsigned int y));
  74. TERM_PUBLIC void HPGL2_move __P((unsigned int x, unsigned int y));
  75. TERM_PUBLIC void HPGL2_vector __P((unsigned int x, unsigned int y));
  76. TERM_PUBLIC void HPGL2_encode __P((int d));
  77. TERM_PUBLIC int HPGL_text_angle __P((int ang));
  78. TERM_PUBLIC int HPGL2_text_angle __P((int ang));
  79. TERM_PUBLIC void HPGL_reset __P((void));
  80. /* TERM_PUBLIC void HPGL2_reset __P((void)); */
  81. TERM_PUBLIC void PCL_reset __P((void));
  82. TERM_PUBLIC int HPGL2_justify_text __P((enum JUSTIFY just));
  83. #define GOT_HPGL_PROTO
  84. #endif /* TERM_PROTO */
  85.  
  86. #ifndef TERM_PROTO_ONLY
  87. #ifdef TERM_BODY
  88. /*
  89.  * The maximum plot size, in plotter units:
  90.  */
  91.  
  92. #define HPGL_PUPI    1016    /* Plotter units per inch */
  93.   
  94. #define HPGL_XMAX_A    10000
  95. #define HPGL_YMAX_A    7500
  96.   
  97. #define HPGL_XMAX_B    15200
  98. #define HPGL_YMAX_B    10000
  99.  
  100. #define HPGL_XMAX    HPGL_XMAX_A
  101. #define HPGL_YMAX    HPGL_YMAX_A
  102.   
  103. #define PCL_XMAX    HPGL_XMAX_A
  104. #define PCL_YMAX    (HPGL_YMAX_A-60)
  105.  
  106. /*
  107.  * Tic sizes
  108.  */
  109.  
  110. #define HPGL_VTIC    (HPGL_YMAX/70)
  111. #define HPGL_HTIC    (HPGL_YMAX/70)
  112.  
  113. #define PCL_VTIC    (PCL_YMAX/70)
  114. #define PCL_HTIC    (PCL_YMAX/70)
  115.  
  116. /*
  117.  * Font size for HPGL
  118.  */
  119.  
  120. #define HPGL_VCHAR    (HPGL_YMAX/100*32/10) /* 3.2% */
  121. #define HPGL_HCHAR    (HPGL_XMAX/100*12/10) /* 1.2% */
  122.  
  123. /*
  124.  * Font size for HPGL/2
  125.  */
  126.  
  127. #define HPGL2_DEF_POINT    14    /* Height of font */
  128.  
  129. #define HPGL2_DEF_PITCH    (3 * 72 / (HPGL2_DEF_POINT * 2))
  130. #define HPGL2_VCHAR    ((int) HPGL_PUPI * HPGL2_DEF_POINT / 72)
  131. #define HPGL2_HCHAR    (HPGL2_VCHAR * 2 / 3)
  132.  
  133. /*
  134.  * Control constants
  135.  */
  136.  
  137. #define DOWN        0    /* Pen is down */
  138. #define UP         1    /* Pen is up */
  139. #define UNKNOWN        -10    /* Unknown status for lots of things */
  140.  
  141. /*
  142.  * For Polyline Encoded, either use base 64 or base 32.
  143.  * Save space with base 64, but get 8-bit characters.
  144.  */
  145.  
  146. #define HPGL2_BASE64 TRUE
  147.  
  148. #if HPGL2_BASE64
  149. #define HPGL2_BITS 6
  150. #define HPGL2_LOW_OFFS 63
  151. #define HPGL2_HIGH_OFFS 191
  152. #define HPGL2_MASK 63
  153. #else
  154. #define HPGL2_BITS 5
  155. #define HPGL2_LOW_OFFS 63
  156. #define HPGL2_HIGH_OFFS 95
  157. #define HPGL2_MASK 31
  158. #endif
  159.  
  160. /*
  161.  * Data structures for options
  162.  */
  163.  
  164. struct HPGL2_font_str {
  165.     char           *compare,
  166.                    *name;
  167.     int             symbol_set,
  168.                     spacing;
  169.     double          pitch,
  170.                     height;
  171.     int             posture,
  172.                     stroke_weight,
  173.                     typeface;
  174. };
  175.  
  176. struct PCL_mode_str {
  177.     char           *compare,
  178.                    *name,
  179.                    *command;
  180.     int             xmax,
  181.                     ymax;
  182. };
  183.  
  184. /*
  185.  * The default font goes first.  Although it is the ugliest,  the
  186.  * stick font is probably supported by the most devices, so it
  187.  * becomes the default.
  188.  */
  189.  
  190. static struct HPGL2_font_str GPFAR HPGL2_font_table[] = {
  191.         {"u$nivers", "univers", 277, 1, 0.0, HPGL2_DEF_POINT, 0, 0, 4148},
  192.          {"s$tick", "stick", 277, 0, HPGL2_DEF_PITCH, 0.0, 0, 0, 48},
  193.        {"c$g_times", "cg_times", 277, 1, 0.0, HPGL2_DEF_POINT, 0, 0, 4101}
  194. };
  195.  
  196. #define HPGL2_FONTS (sizeof(HPGL2_font_table) / sizeof (struct HPGL2_font_str))
  197. static struct HPGL2_font_str *HPGL2_font = &HPGL2_font_table[0];
  198.  
  199. /*
  200.  * The default mode goes first.  Landscape style plots are probably the
  201.  * most compatable with other HPGL devices.
  202.  */
  203.  
  204. static struct PCL_mode_str GPFAR PCL_mode_table[] = {
  205.           {"l$andscape", "landscape", "\033&l1O", PCL_XMAX, PCL_YMAX},
  206.          {"p$ortrait", "portrait", "\033&l0O", PCL_YMAX, PCL_XMAX}
  207. };
  208.  
  209. #define PCL_MODES (sizeof(PCL_mode_table) / sizeof (struct PCL_mode_str))
  210. static struct PCL_mode_str *PCL_mode = &PCL_mode_table[0];
  211.  
  212. /*
  213.  * Various line types and widths to distinguish data sets
  214.  */
  215.  
  216. static char    *HPGL2_lt[] = {"", "4,2", "5,2", "6,2", "7,2", "8,2"},
  217.                *HPGL2_pw[] = {".15", ".12", ".08"};
  218.  
  219. #define HPGL2_LINETYPES (sizeof(HPGL2_lt) / sizeof(char *))
  220. #define HPGL2_PENWIDTHS (sizeof(HPGL2_pw) / sizeof(char *))
  221.  
  222. /*
  223.  * Static variables to keep track of where we are, etc.
  224.  */
  225.  
  226. static int      HPGL_ang = 0,
  227.                 HPGL_x = UNKNOWN,
  228.                 HPGL_y = UNKNOWN,
  229.                 HPGL_penstate = UNKNOWN,
  230.                 HPGL_pentype = UNKNOWN,
  231.                 HPGL2_in_pe,
  232.                 HPGL2_lost;
  233.  
  234. /*
  235.  * The subroutines, grouped by function for different versions.
  236.  */
  237.  
  238. static int HPGL_numpen,HPGL_eject;
  239.  
  240. void HPGL_options ()
  241. {
  242.   HPGL_numpen = 6; /* default to six pens */
  243.   HPGL_eject = 0; /* default to no eject */
  244.  
  245.   while (!END_OF_COMMAND) {
  246.     if (almost_equals(c_token,"eje$ct")) HPGL_eject = 1;
  247.     else if (isanumber(c_token)) {
  248.         HPGL_numpen = (int) real(&token[c_token].l_val);
  249.         if (HPGL_numpen <= 0) {
  250.         HPGL_numpen = 6;
  251.         int_error ("Number of pens must be positive", c_token);
  252.         }
  253.     }
  254.     else int_error ("expecting \"eject\" or number of pens", c_token);
  255.  
  256.     c_token++;
  257.   }
  258.  
  259.  
  260.   sprintf(term_options,"%d pens %s",HPGL_numpen,
  261.   HPGL_eject ? "eject" : "noeject");
  262. }
  263.  
  264. void HPGL2_options ()
  265. {
  266.     struct termentry *t = term;
  267.     int             i;
  268.     double          point_size;
  269.     char       tmp_options[MAX_ID_LEN];
  270.     if (!END_OF_COMMAND) {
  271.     for (i = 0; i < HPGL2_FONTS &&
  272.          !almost_equals (c_token, HPGL2_font_table[i].compare); i++);
  273.     if (i < HPGL2_FONTS) {
  274.         HPGL2_font = &HPGL2_font_table[i];
  275.     } else
  276.         int_error ("expecting font: stick, cg_times, or univers", c_token);
  277.     c_token++;
  278.     if (!END_OF_COMMAND) {
  279.         if ((point_size = real(&token[c_token].l_val)) > 0.0) {
  280.         t->v_char = (int) HPGL_PUPI *point_size / 72;
  281.         t->h_char = t->v_char * 2 / 3;
  282.         if (HPGL2_font->spacing)
  283.             HPGL2_font->height = point_size;
  284.         else
  285.             HPGL2_font->pitch = 72 * 3 / (point_size * 2);
  286.         } else
  287.         int_error ("expecting font point size: real number",c_token);
  288.         c_token++;
  289.     }
  290.     }
  291.     sprintf (tmp_options, " %s", HPGL2_font->name);
  292.     strcat(term_options,tmp_options);
  293.     if (HPGL2_font->spacing){
  294.     sprintf (tmp_options, " %f",
  295.           HPGL2_font->height);
  296.     strcat(term_options,tmp_options);
  297.     }else{
  298.     sprintf (tmp_options, " %f",
  299.           HPGL2_font->pitch);
  300.         strcat(term_options,tmp_options);
  301.     }
  302. }
  303.  
  304. void PCL_options ()
  305. {
  306.     int             i;
  307.     if (!END_OF_COMMAND) {
  308.     for (i = 0; i < PCL_MODES &&
  309.          !almost_equals (c_token, PCL_mode_table[i].compare); i++);
  310.     if (i < PCL_MODES)
  311.         PCL_mode = &PCL_mode_table[i];
  312.     else
  313.         int_error ("expecting mode: portrait or landscape", c_token);
  314.     c_token++;
  315.     }
  316.     sprintf (term_options, " %s", PCL_mode->name);
  317.     HPGL2_options ();
  318. }
  319.  
  320. void HPGL_init ()
  321. {
  322. }
  323.  
  324. /* void HPGL2_init ()
  325. {
  326. } */
  327.  
  328. void PCL_init ()
  329. {
  330.     struct termentry *t = term;
  331. /*
  332.  * Reset printer, set to one copy, orientation of user's choice.
  333.  * Make the change to the new orientation all at once.
  334.  */
  335.     fprintf (outfile, "\033E\033&l1X%s\n", PCL_mode->command);
  336.     t->xmax = PCL_mode->xmax;
  337.     t->ymax = PCL_mode->ymax;
  338. }
  339.  
  340. void HPGL_graphics()
  341. {
  342.     fputs("\033.Y\n\033.I81;;17:\033.N;19:\033.M500:\n",outfile);
  343. /*           1
  344.     1. enable eavesdropping
  345. */
  346.     fprintf(outfile,
  347.     "IN;\nSC0,%d,0,%d;\nSR%f,%f;\n",
  348.         HPGL_XMAX,HPGL_YMAX,
  349.         ((double)(HPGL_HCHAR)*200/3/HPGL_XMAX),
  350.         ((double)(HPGL_VCHAR)*100/2/HPGL_YMAX) );
  351. /*     1    2             3 
  352.     1. reset to power-up defaults
  353.     2. set SCaling
  354.     3. set character size
  355. */
  356.     HPGL_ang = 0;
  357. }
  358.  
  359. void HPGL2_graphics ()
  360. {
  361. /*
  362.  * IN - Initialize
  363.  * SP - Select pen
  364.  * SD - Set default font
  365.  */
  366.     fprintf (outfile, "INSP1SD1,%d,2,%d,",
  367.          HPGL2_font->symbol_set, HPGL2_font->spacing);
  368.     if (HPGL2_font->spacing)
  369.     fprintf (outfile, "4,%f,", HPGL2_font->height);
  370.     else
  371.     fprintf (outfile, "3,%f,", HPGL2_font->pitch);
  372.     fprintf (outfile, "5,%d,6,%d,7,%d\n", HPGL2_font->posture,
  373.          HPGL2_font->stroke_weight, HPGL2_font->typeface);
  374. /*
  375.  * Control variables
  376.  */
  377.     HPGL_ang = 0;        /* Horizontal */
  378.     HPGL2_in_pe = FALSE;    /* Not in PE command */
  379.     HPGL2_lost = TRUE;        /* Pen position is unknown */
  380.     HPGL_penstate = UP;        /* Pen is up */
  381. }
  382.  
  383. void PCL_graphics ()
  384. {
  385. /*
  386.  * Enter HPGL/2 graphics mode
  387.  */
  388.     fputs ("\033%0B", outfile);
  389.     HPGL2_graphics ();
  390. }
  391.  
  392. void HPGL_text ()
  393. {
  394.     if (HPGL_eject == 0) {
  395.      fputs ("PUSP0;\033.Z\n\0", outfile);
  396. /*         1 2   3
  397.     1. pen up
  398.     2. park pen
  399.     3. disable eavesdropping
  400. */
  401.     }
  402.     else
  403.     {
  404.          fputs ("PUSP0;PG;\033.Z\n\0", outfile);
  405. /*         1 2   3  4
  406.     1. pen up
  407.     2. park pen
  408.     3. page eject
  409.     4. disable eavesdropping
  410. */
  411.     }
  412.     HPGL_penstate = UP;
  413. }
  414.  
  415. #if 0 /* not used */
  416. void HPGL2_text ()
  417. {
  418. /*
  419.  * If in Polyline Encoded command, leave Polyline Encoded command
  420.  */
  421.     if (HPGL2_in_pe) {
  422.     fputs (";\n", outfile);
  423.     HPGL2_in_pe = 0;
  424.     }
  425. /*
  426.  * Pen up, park pen
  427.  */
  428.     fputs ("PUSP0;", outfile);
  429. }
  430. #endif
  431.  
  432. void PCL_text ()
  433. {
  434.     if (HPGL2_in_pe) {
  435.     fputs (";\n", outfile);
  436.     HPGL2_in_pe = 0;
  437.     }
  438. /*
  439.  * Go into PCL mode and eject the page
  440.  */
  441.     fputs ("\033%1A\033&l0H\n\0", outfile);
  442. }
  443.  
  444. void HPGL_linetype (linetype)
  445.     int             linetype;
  446. {
  447. /* allow for set number of pens */
  448.     linetype = (linetype + 2) % HPGL_numpen + 1;
  449. /* only select pen if necessary */
  450.     if (HPGL_pentype != linetype) {
  451.     fprintf (outfile, "PU;\nSP%d;\n", linetype);
  452.     HPGL_pentype = linetype;
  453.     HPGL_penstate = UP;
  454.     }
  455. }
  456.  
  457. void HPGL2_linetype (linetype)
  458.     int             linetype;
  459. {
  460. /*
  461.  * If in Polyline Encoded command, leave Polyline Encoded command
  462.  */
  463.     if (HPGL2_in_pe) {
  464.     fputs (";\n", outfile);
  465.     HPGL2_in_pe = 0;
  466.     }
  467. /*
  468.  * Allow for lots of linetypes
  469.  */
  470.     if (linetype >= 0)
  471.     linetype = linetype % (HPGL2_LINETYPES * HPGL2_PENWIDTHS);
  472.     if (linetype != HPGL_pentype) {
  473.     if (linetype >= 0) {
  474.         fprintf (outfile, "PW%sLT%s",
  475.              HPGL2_pw[linetype / HPGL2_LINETYPES],
  476.              HPGL2_lt[linetype % HPGL2_LINETYPES]);
  477.     } else if (linetype == -2)
  478. /*
  479.  * Borders and tics
  480.  */
  481.         fprintf (outfile, "PW.2LT");
  482.     else if (linetype == -1)
  483. /*
  484.  * Axes and grids
  485.  */
  486.         fprintf (outfile, "PW.1LT1,.25");
  487.     HPGL_pentype = linetype;
  488.     }
  489. }
  490.  
  491. void HPGL_put_text (x, y, str)
  492.     unsigned int    x,
  493.                     y;
  494.     char           *str;
  495. {
  496.     if (HPGL_ang == 1)
  497.     HPGL_move (x + HPGL_VCHAR / 4, y);
  498.     else
  499.     HPGL_move (x, y - HPGL_VCHAR / 4);
  500.     fprintf (outfile, "LB%s\003\n", str);
  501. }
  502.  
  503. void HPGL2_put_text (x, y, str)
  504.     unsigned int    x,
  505.                     y;
  506.     char           *str;
  507. {
  508.     struct termentry *t = term;
  509. /*
  510.  * Position the pen
  511.  */
  512.     if (HPGL_ang == 1)
  513.     HPGL2_move (x + t->v_char / 4, y);
  514.     else
  515.     HPGL2_move (x, y - t->v_char / 4);
  516. /*
  517.  * If in Polyline Encoded command, leave Polyline Encoded command
  518.  */
  519.     if (HPGL2_in_pe) {
  520.     fputs (";\n", outfile);
  521.     HPGL2_in_pe = 0;
  522.     }
  523. /*
  524.  * Print the text string
  525.  */
  526.     fprintf (outfile, "LB%s\003\n", str);
  527.     HPGL2_lost = 1;
  528. }
  529. /*
  530.  * Some early HPGL plotters (e.g. HP7220C) require the
  531.  * Pen Up/Down and Pen (move) Absolute commands to be separate.
  532.  */
  533.  
  534. void HPGL_move (x, y)
  535.     unsigned int    x,
  536.                     y;
  537. {
  538.     if (HPGL_x != x || HPGL_y != y) {        /* only move if necessary */
  539.     fprintf (outfile, "PU;PA%d,%d;\n", x, y);
  540.     HPGL_penstate = UP;
  541.     HPGL_x = x;
  542.     HPGL_y = y;
  543.     }
  544. }
  545.  
  546. void HPGL_vector (x, y)
  547.     unsigned int    x,
  548.                     y;
  549. {
  550.     if (HPGL_penstate != DOWN) {
  551.     fprintf (outfile, "PD;PA%d,%d;\n", x, y);
  552.     HPGL_penstate = DOWN;
  553.     } else
  554.     fprintf (outfile, "PA%d,%d;\n", x, y);
  555.     HPGL_x = x;
  556.     HPGL_y = y;
  557. }
  558.  
  559. void HPGL2_move (x, y)
  560.     unsigned int    x,
  561.                     y;
  562. {
  563.     register int    dx,
  564.                     dy;
  565.     if (HPGL2_in_pe) {
  566.     dx = x - HPGL_x;
  567.     dy = y - HPGL_y;
  568.     fputs ("<", outfile);
  569.     } else {
  570. #if HPGL2_BASE64
  571.     fputs ("PE<", outfile);
  572. #else
  573.     fputs ("PE7<", outfile);
  574. #endif
  575.     if (HPGL2_lost) {
  576.         dx = x;
  577.         dy = y;
  578.         HPGL2_lost = 0;
  579.         fputs ("=", outfile);
  580.     } else {
  581.         dx = x - HPGL_x;
  582.         dy = y - HPGL_y;
  583.     }
  584.     HPGL2_in_pe = 1;
  585.     }
  586. #if HPGL2_EXPLICIT_PD
  587.     if (HPGL_penstate == DOWN)
  588.     HPGL_penstate = UP;
  589. #endif
  590.     HPGL2_encode (dx);
  591.     HPGL2_encode (dy);
  592.     fputs("\n",outfile);
  593.     HPGL_x = x;
  594.     HPGL_y = y;
  595. }
  596.  
  597. void HPGL2_vector (x, y)
  598.     unsigned int    x,
  599.                     y;
  600. {
  601.     register int    dx,
  602.                     dy;
  603.     if (HPGL2_in_pe) {
  604.     dx = x - HPGL_x;
  605.     dy = y - HPGL_y;
  606.     } else {
  607. #if HPGL2_BASE64
  608.     fputs ("PE", outfile);
  609. #else
  610.     fputs ("PE7", outfile);
  611. #endif
  612.     if (HPGL2_lost) {
  613.         dx = x;
  614.         dy = y;
  615.         HPGL2_lost = 0;
  616.         fputs ("=", outfile);
  617.     } else {
  618.         dx = x - HPGL_x;
  619.         dy = y - HPGL_y;
  620.     }
  621.     HPGL2_in_pe = 1;
  622.     }
  623. #if HPGL2_EXPLICIT_PD
  624. /*
  625.  * Put the pen down in the current position,
  626.  * relative vector of 0,0.
  627.  */
  628.     if (HPGL_penstate == UP) {
  629.     fputc ((char) HPGL2_HIGH_OFFS, outfile);
  630.     fputc ((char) HPGL2_HIGH_OFFS, outfile);
  631.     HPGL_penstate = DOWN;
  632.     }
  633. #endif
  634.     HPGL2_encode (dx);
  635.     HPGL2_encode (dy);
  636.     fputs("\n",outfile);
  637.     HPGL_x = x;
  638.     HPGL_y = y;
  639. }
  640.  
  641. /*
  642.  * Routine to encode position in base 32 or base 64 characters
  643.  */
  644.  
  645. void HPGL2_encode (d)
  646.     register int    d;
  647. {
  648.     register int    c;
  649.     if ((d <<= 1) < 0)
  650.     d = 1 - d;
  651.     do {
  652.     c = d & HPGL2_MASK;
  653.     d >>= HPGL2_BITS;
  654.     if (d > 0)
  655.         fputc ((char) (c + HPGL2_LOW_OFFS), outfile);
  656.     else
  657.         fputc ((char) (c + HPGL2_HIGH_OFFS), outfile);
  658.     } while (d > 0);
  659. }
  660.  
  661. int
  662. HPGL_text_angle (ang)
  663.     int             ang;
  664. {
  665.     HPGL_ang = ang;
  666.     if (ang == 1)
  667. /*
  668.  *  Vertical
  669.  */
  670.     fprintf (outfile, "DI0,1;\n");
  671.     else
  672. /*
  673.  * Horizontal
  674.  */
  675.     fprintf (outfile, "DI1,0;\n");
  676.     return TRUE;
  677. }
  678.  
  679. int
  680. HPGL2_text_angle (ang)
  681.     int             ang;
  682. {
  683. /*
  684.  * If in Polyline Encoded command, leave Polyline Encoded command
  685.  */
  686.     if (HPGL2_in_pe) {
  687.     fputs (";", outfile);
  688.     HPGL2_in_pe = 0;
  689.     }
  690.     if (ang == 1)
  691. /*
  692.  *  Vertical
  693.  */
  694.     fprintf (outfile, "DI0,1");
  695.     else
  696. /*
  697.  * Horizontal
  698.  */
  699.     fprintf (outfile, "DI1,0");
  700.     HPGL_ang = ang;
  701.     return TRUE;
  702. }
  703.  
  704. void HPGL_reset ()
  705. {
  706. /*
  707.  * do nothing
  708.  */
  709. }
  710.  
  711. #if 0
  712. void HPGL2_reset ()
  713. {
  714. /*
  715.  * Park the pen
  716.  * Advance a page
  717.  * End with ";"
  718.  */
  719.     fputs ("SP0PG;\n", outfile);
  720. }
  721. #endif
  722.  
  723. void PCL_reset ()
  724. {
  725. /*
  726.  * Return to PCL mode
  727.  * Printer reset (conditional eject)
  728.  */
  729.     fputs ("\033%0A\033E\n", outfile);
  730. }
  731.  
  732. int HPGL2_justify_text (just)
  733.     enum JUSTIFY just;
  734. {
  735. /*
  736.  * If in Polyline Encoded command, leave Polyline Encoded command
  737.  */
  738.     if (HPGL2_in_pe) {
  739.     fputs (";\n", outfile);
  740.     HPGL2_in_pe = 0;
  741.     }
  742.     switch (just) {
  743.     case LEFT:
  744.     fputs ("LO1", outfile);
  745.     break;
  746.     case CENTRE:
  747.     fputs ("LO4", outfile);
  748.     break;
  749.     case RIGHT:
  750.     fputs ("LO7", outfile);
  751.     break;
  752.     default:
  753.     return 0;
  754.     }
  755.     return 1;
  756. }
  757.  
  758. #endif /* TERM_BODY */
  759.  
  760. #ifdef TERM_TABLE
  761. TERM_TABLE_START(hpgl_driver)
  762.    "hpgl", "HP7475 and (hopefully) lots of others [number of pens] [eject]",
  763.            HPGL_XMAX, HPGL_YMAX, HPGL_VCHAR, HPGL_HCHAR,
  764.            HPGL_VTIC, HPGL_HTIC, HPGL_options, HPGL_init, HPGL_reset,
  765.            HPGL_text, null_scale, HPGL_graphics, HPGL_move, HPGL_vector,
  766.            HPGL_linetype, HPGL_put_text, HPGL_text_angle, 
  767.            null_justify_text, do_point, do_arrow, set_font_null
  768. TERM_TABLE_END(hpgl_driver)
  769. #undef LAST_TERM
  770. #define LAST_TERM hpgl_driver
  771. TERM_TABLE_START(pcl5_driver)
  772.     "pcl5", "HP LaserJet III [mode] [font] [point]",
  773.     PCL_XMAX, PCL_YMAX, HPGL2_VCHAR, HPGL2_HCHAR,
  774.     PCL_VTIC, PCL_HTIC, PCL_options, PCL_init, PCL_reset,
  775.     PCL_text, null_scale, PCL_graphics, HPGL2_move, HPGL2_vector,
  776.     HPGL2_linetype, HPGL2_put_text, HPGL2_text_angle,
  777.     HPGL2_justify_text, do_point, do_arrow, set_font_null
  778. TERM_TABLE_END(pcl5_driver)
  779. #undef LAST_TERM
  780. #define LAST_TERM pcl5_driver
  781. #endif /* TERM_TABLE */
  782.  
  783. #endif /* TERM_PROTO_ONLY */
  784.